﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DSAAssignment.Controllers
{
    public class WebsiteController : Controller
    {
        //
        // GET: /Website/

        public ActionResult Index()
        {
            return View();
        }

        [ChildActionOnly]
        public ActionResult Menu()
        {
            
            IEnumerable<Common.Menu> Menus = new UserServ.UserServicesClient().GetMenus(1);
            return PartialView("Menu", Menus);
        }

        [ChildActionOnly]
        public ActionResult SubMenu()
        {
            IEnumerable<Common.Category> subMenu = new ProductServ.ProductServicesClient().GetAllCategories();
            return PartialView("SubMenu", subMenu);
        }

        [ChildActionOnly]
        public ActionResult SortBy()
        {
            List<Common.Product> list = new ProductServ.ProductServicesClient().GetAllProducts().OrderByDescending(x => x.Name).ToList();
            return PartialView("SortBy", list);
        }

        [ChildActionOnly]
        public ActionResult Comments(int ProductId)
        {
            List<Common.Comment> list = new ProductServ.ProductServicesClient().getComments(ProductId).ToList();
            return PartialView("Comments", list);
        }

        public PartialViewResult Product(int id)
        {
            Common.Views.ProductDetails p = new ProductServ.ProductServicesClient().GetProductDetailsByID(id,HttpContext.User.Identity.Name);
            return PartialView("_Product", p);
        }

        [ChildActionOnly]
        public ActionResult FaultsList()
        {
            List<DSAAssignment.Models.FaultModel> list = new List<Models.FaultModel>();
            foreach (Common.UserProductFault upf in new FaultServ.FaultServiceClient().getAllFaults())
            {
                Common.Fault f = new FaultServ.FaultServiceClient().getFaultStatusByID((int)upf.FaultID);
                DSAAssignment.Models.FaultModel model = new Models.FaultModel();

                model.FaultID = (int)upf.FaultID;
                model.FaultStatus = upf.Fault.Fault1;
                model.ProductID = (int)upf.ProductID;
                model.ProductName = upf.Product.Name;
                model.FaultDescription = upf.Fault.Description;
                model.UserName = upf.UserName;
                model.Date = upf.Date;
                model.FaultReports = new FaultServ.FaultServiceClient().GetAllFaultStatus();
                model.FaultReportsList = new SelectList(new FaultServ.FaultServiceClient().GetAllFaultStatus(), "ID", "Fault1");
                list.Add(model);
            }

            return PartialView("FaultList", list);

        }
    }
}
